<template>
    <div>
        <div>
            用户：
            <template>
                <el-select v-model="user" placeholder="请选择">
                    <el-option v-for="item in userlist" :key="item.id" :label="item.name" :value="item.id">
                    </el-option>
                </el-select>
            </template>
            <br><br>

            开始时间：
            <div class="block">
                <el-date-picker value-format="yyyy-MM-dd HH:mm:ss" v-model="stime" type="datetime" placeholder="选择日期时间">
                </el-date-picker>
            </div><br>

            结束时间：
            <div class="block">
                <el-date-picker value-format="yyyy-MM-dd HH:mm:ss" v-model="etime" type="datetime" placeholder="选择日期时间">
                </el-date-picker>
            </div>
            <br>

            天数：
            <el-input v-model="days"></el-input>
            <br><br>

            理由：
            <template>
                <el-select v-model="type" placeholder="请选择">
                    <el-option v-for="item in type1" :key="item.id" :label="item.name" :value="item.id">
                    </el-option>
                </el-select>
            </template>
            <br><br>

            下一任：
            <el-input v-model="nextid"></el-input>
            <br>
        </div>

        <div>
            <el-button @click="send">请假</el-button>
        </div>
    </div>
</template>

<script>
export default {
    name: 'ZiYuan',
    data() {
        return {
            user: "",
            stime: "",
            etime: "",
            days: "",
            type: "",
            nextid: "",

            type1: [
                { "id": 1, 'name': "病假" },
                { "id": 2, 'name': "事假" },
            ],
            userlist:[],
        };
    },
    props: {},

    components: {},

    created() { },

    mounted() {
        this.getuser();
    },

    methods: {
        getuser(){
            this.axios.get("user")
            .then((resp) => {
                console.log("获取用户:", resp)
                this.userlist=resp.data.msg
            }).catch((err) => {
                console.log(err)
            });
        },

        send(){
            this.axios.post("leave",{
                userid:this.user,
                stime:this.stime,
                etime:this.etime,
                days:this.days,
                type:this.type,
                nextid:this.nextid,
            })
            .then((resp) => {
                console.log("请假", resp)
                this.user = ""
                this.stime = ""
                this.etime = ""
                this.days = ""
                this.type = ""
                this.nextid = ""
            }).catch((err) => {
                console.log(err)
            });
        }
    },

    computed: {},

    watch: {},

    directives: {},

    filters: {}
};
</script>

<style scoped>

</style>
